<% if can? :update, doc %>
<%
  open_attr = action_name == "share" ? " open" : ""
%>
<details
  class="doc-share-button-box dropdown details-overlay details-reset d-inline-block hide-sm mr-4"
  <%= open_attr %>
>
  <summary class="link-gray-dark"><%= icon_tag("share", label: t(".Share")) %></summary>
  <div class="doc-share-button-box dropdown-menu dropdown-menu-sw p-4" style="width: 420px">
    <h4 class="mb-2"><%= t(".Share doc") %></h4>
    <% if doc.share %>
      <p class="description f6"><%= t(".Everyone can visits this doc with the share link") %></p>
      <div class="form-group mb-2">
        <input type="text" readonly value="<%= doc.share.to_url %>" class="form-control" />
      </div>
      <div class="share-user mb-2 f6">
        <%= user_name_tag(doc.share&.user) %> <span class="text-gray-light"><%= t(".opened share at") %> <%= timeago doc.share.created_at %></span>
      </div>
      <div class="action float-right">
        <%= link_to t(".Unshare"), doc.to_path("/share?unshare=1"), class: "btn btn-link text-danger hover-danger btn-cancel-share mr-3", method: :post, remote: true, "disable-with": t(".Submiting") %>
        <clipboard-copy class="btn btn-primary" data-clipboard-text="<%= doc.share.to_url %>"><%= icon_tag("copy-link") %><%= t(".Copy Link") %></clipboard-copy>
      </div>
    <% else %>
      <p class="description mb-2"><%= t(".Create a share link to allow anyone to visit this doc") %></p>
      <div class="action float-right"><%= link_to t(".Open share"), doc.to_path("/share"), class: "btn btn-open-share btn-primary", method: :post, remote: true, "disable-with": t(".Submiting") %></div>
    <% end %>
  </div>
</details>
<% end %>